/**
	This file is part of Fighting Field.

    Fighting Field is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Fighting Field is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Fighting Field.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef FF_WIDGET_H
#define FF_WIDGET_H

#include "Prerequisites.h"

namespace FF
{
	class GuiListener;
}

namespace Ogre
{
	class TextAreaOverlayElement;
}

namespace FF
{
	// enumerator values for widget tray anchoring locations
	struct TrayLocation
	{
		enum Val
		{
			TopLeft,
			Top,
			TopRight,
			Left,
			Center,
			Right,
			BottomLeft,
			Bottom,
			BottomRight,
			None
		};
	};

	class Widget
	{
	public:
		Widget();
		virtual ~Widget() {}

		void Cleanup();

		// Static utility method to recursively delete an overlay element plus
		// all of its children from the system.
		static void NukeOverlayElement(Ogre::OverlayElement* element);

		// Static utility method to check if the cursor is over an overlay element.
		static bool IsCursorOver(Ogre::OverlayElement* element, const Ogre::Vector2& cursorPos, Ogre::Real voidBorder = 0);

		// Static utility method used to get the cursor's offset from the center
		// of an overlay element in pixels.
		static Ogre::Vector2 CursorOffset(Ogre::OverlayElement* element, const Ogre::Vector2& cursorPos);

		// Static utility method used to get the width of a caption in a text area.
		static Ogre::Real GetCaptionWidth(const Ogre::DisplayString& caption, Ogre::TextAreaOverlayElement* area);

		// Static utility method to cut off a string to fit in a text area.
		static void FitCaptionToArea(const Ogre::DisplayString& caption, Ogre::TextAreaOverlayElement* area, Ogre::Real maxWidth);

		Ogre::OverlayElement* GetOverlayElement();
		const Ogre::String& GetName();
		TrayLocation::Val GetTrayLocation();

		void Hide();
		void Show();
		bool IsVisible();

		// callbacks
		virtual void _OnCursorPressed(const Ogre::Vector2& cursorPos) {}
		virtual void _OnCursorReleased(const Ogre::Vector2& cursorPos) {}
		virtual void _OnCursorMoved(const Ogre::Vector2& cursorPos) {}
		virtual void _OnFocusLost() {}

		// internal methods used by GuiManager. do not call directly.
		void _AssignToTray(TrayLocation::Val trayLoc) { mGuiLoc = trayLoc; }
		void _AssignListener(GuiListener* listener) { mListener = listener; }

	protected:
		Ogre::OverlayElement* mElement;
		TrayLocation::Val mGuiLoc;
		GuiListener* mListener;
	};

	typedef std::vector<Widget*> WidgetList;
	typedef Ogre::VectorIterator<WidgetList> WidgetIterator;
}

#endif